<div class="container"> 
	<div class="row"> 
		<div class="panel panel-info">
			<div class="panel-heading">
				<div class="panel-title">Review Your Order</div>
			</div>
			<div class="panel-body">
				<?php if($response):?>
				<div class="alert alert-danger alert-dismissable">
					<button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
					<?php echo $response; ?>
				</div>
				<?php endif;?>
				<form role="form" action="" method="post" id="purchaseform">
					<h4>Payment Information</h4>
					<div class="well well-sm">
						<div class="row">
							<div class="col-md-4">
								<img src="<?php echo base_url('assets/front/img/card.png')?>" class="img-responsive"/>
							</div>
							<div class="col-md-8">
								<div class="row">
									<div class="col-md-4">
										<div class="form-group">
											<label for="cardname">Type of Credit Card</label>
											<select class="form-control" name="CardType" id="CardType">
												<option value="">Select card Type</option>
												<option value="AmEx" <?=($CardType=='AmEx') ? "selected='selected'" : ""?>>American Express</option>
												<option value="Discover" <?=($CardType=='Discover') ? "selected='selected'" : ""?>>Discover</option>
												<option value="Mastercard" <?=($CardType=='Mastercard') ? "selected='selected'" : ""?>>MasterCard</option>
												<option value="Visa" <?=($CardType=='Visa') ? "selected='selected'" : ""?>>VISA</option>
											</select>
										</div>
									</div>
									<div class="col-md-4">
										<div class="form-group">
											<label for="cardname">Cardholder's Name</label>
											<div class="input-group">
												<input type="text" class="form-control" id="CCName" name="CCName" value="<?=$CCName?>" placeholder="Cardholder's Name" />
												<span class="input-group-addon"><span class="glyphicon glyphicon-user"></span></span>
											</div>
										</div>
									</div>
									<div class="col-md-4">
										 <div class="form-group">
											<label for="cardNumber">Credit Card Number</label>
											<div class="input-group">
												<input type="text" class="form-control" id="CreditCardNumber" name="CreditCardNumber" value="<?=$CreditCardNumber?>" placeholder="Credit Card Number"/>
												<span class="input-group-addon"><span class="glyphicon glyphicon-lock"></span></span>
											</div>
										</div>
									</div>
								</div>
								<div class="row">
									<div class="col-md-3">
										 <div class="form-group">
											<label for="cardNumber">Expire Month</label>
											<select class="form-control" name="CreditCardExpMonth" id="CreditCardExpMonth">
												<option>Month</option>
												<?php 
												$montharray=array("Jan","Feb","Mar","Apr","May","June","July","Aug","Sep","Oct","Nov","Dec");
												for ($month = 1; $month <=12; $month++)
												{
													$m=$month-1;
													if($month <=9)
													{
														$month='0'.$month;
													}
													echo "<option value=$month";
													echo ($CreditCardExpMonth==$month)? " selected='selected'" : "";
													echo ">$montharray[$m]($month)</option>";
												}
												?>
											</select>
										</div>
									</div>
									<div class="col-md-3">
										 <div class="form-group">
											<label for="cardNumber">Expire Year</label>
											<select class="form-control" name="CreditCardExpYear" id="CreditCardExpYear">
												<?php for($year=date("Y");$year<=date("Y")+10;$year++){
													echo "<option value=$year";
													echo ($CreditCardExpYear==$year)? " selected='selected'" : "";
													echo ">$year</option>";
												}
												?>
												
											</select>
										</div>
									</div>
									<div class="col-md-6">
										 <div class="form-group">
											<label for="cardNumber">CVV2 Number</label>
											<div class="input-group">
												<input type="text" class="form-control" id="CVV2" name="CVV2" value="<?=$CVV2?>" placeholder="Valid CVV Number"/>
												<span class="input-group-addon"><span class="glyphicon glyphicon-lock"></span></span>
											</div>
										</div>
									</div>
								</div>
							</div>
						</div>
					</div>
					
					<h4>Billing Information</h4>
					<div class="well well-sm">
						<div class="row">
							<div class="col-md-4">
								<p>As it appears on your credit card statement.</p>
							</div>
							<div class="col-md-8">
								<div class="row">
									<div class="col-md-4">
										 <div class="form-group">
											<label for="cardNumber">Street Address</label>
											<input type="text" class="form-control" id="CCAddress" name="CCAddress" value="<?=$CCAddress?>" placeholder="Address" />	
										</div>
									</div>
									<div class="col-md-4">
										 <div class="form-group">
											<label for="cardNumber">City</label>
											<input type="text" class="form-control" id="CCCity" name="CCCity" value="<?=$CCCity?>" placeholder="City"/>
										</div>
									</div>
									<div class="col-md-4">
										 <div class="form-group">
											<label for="cardNumber">Country</label>
											<select class="form-control" name="CCCountry" id="CCCountry">
												<option value="">Select Country</option>
												<?php foreach($countries as $country){?>
												<option value="<?=$country['name']?>" phonecode="<?=$country['phone_code']?>" <?php if($CCCountry==$country['name']) echo "selected='selected'";?>><?=$country['name']?></option>
												<?}?>
											</select>
										</div>
									</div>
								</div>
								<div class="row">
									<div class="col-md-4">
										<div class="form-group">
											<div class="state">
												<label for="cardNumber">State</label>
												<select class="form-control" name="CCState" id="CCState">
													<?php foreach($us_states as $states){?>
													<option value="<?=$states['code']?>" <?php if($CCState==$states['code']) echo "selected='selected'";?>><?=$states['name']?></option>
													<?}?>
												</select>
											</div>
											<div class="province">
												<label for="cardNumber">Province</label>
												<input type="text" class="form-control" name="CCProvince" id="CCProvince" value="<?=$CCProvince?>" placeholder="Province">
											</div>
										</div>
									</div>
									<div class="col-md-4">
										 <div class="form-group">
											<label for="cardNumber">Postal/Zip</label>
											<input type="text" class="form-control" id="CCZip" name="CCZip" value="<?=$CCZip?>" placeholder="Zip"/>
										</div>
									</div>
									<div class="col-md-4">
										 <div class="form-group">
											<label for="cardNumber">Phone</label>
											<div class="row">
												<div class="col-md-5">
													<select class="form-control" name="CountryCode" id="CountryCode">
														<?php foreach($countries as $country){?>
														<option value="<?=$country['phone_code']?>" <?php if($CountryCode==$country['phone_code']) echo "selected='selected'";?>><?=$country['phone_code']?></option>
														<?}?>
													</select>
												</div>
												<div class="col-md-7">
													<input type="text" class="form-control" id="PhoneNumber" name="PhoneNumber" value="<?=$PhoneNumber?>" placeholder="Phone Number"/>
												</div>
											</div>
										</div>
									</div>
								</div>
							</div>
						</div>
					</div>
					<h4>Cart Details</h4>
					<div class="well-sm">
						<table class="table">
							<thead>
								<tr class="active">
									<th width="400">Item</th>
									<th width="300">Period/Quantity</th>
									<th width="30">Price</th>
								</tr>
							</thead>
							<tbody class="cartcontent">
								<?php
								$totalprice=0;
								if(!empty($cart))
								{
									
									foreach($cart as $item)
									{?>
										<tr>
											<td>
												<strong><?=$item['name']?></strong><br>
												<small><?=$item['pdesc']?></small>
											</td>
											<td><?php 
												if($item['ptype']=="WebHosting") 
													echo $item['period']."mths for $".$item['price'].'/mth';
												else
												 echo $item['qty']." yr. for $".$item['price'].'/yr';?></td>
											<td>$<?=number_format((float)$item['subtotal'], 2, '.', '')?></td>
										</tr>
										<?
										if ( isset($item['child']))
										{
											foreach($item['child'] as $childitem)
											{?>
												<tr>
													<td>
														<span class="glyphicon glyphicon-hand-right pull-left"></span>
														<div style="padding-left:20px;">
															<strong><?=$childitem['ptype']?></strong><br>				
														</div>
													</td>
													<td><?=$childitem['qty']?> yr. for $<?=$childitem['price']?>/yr.</td>
													<td>$<?=number_format((float)$childitem['subtotal'], 2, '.', '')?></td>
												</tr>
												<?php
												$totalprice+=$childitem['subtotal'];
											}
										}
										$totalprice+=$item['subtotal'];
									}
								}?>
							</tbody>
						</table>
						<div class="well well-sm">
							<span style="color:red">Please verify items and quantities as all sales are final.</span>
							<span class="pull-right" style="font-size: 18px">Total:$<?=number_format((float)$totalprice, 2, '.', '')?></span>
						</div>
					</div>
					<div class="text-right">
						
						<button type="submit" class="btn btn-warning" onclick="return submitform(this)">Place Order</button>
					</div>
				</form>
			</div>
		</div>
	</div>
</div>
<script>
$(function(){
	$('select[name=CCCountry]').change(function(){
		countryname=$(this).val();
		//$('#CountryCode').val());
		$('#CountryCode').val($('#CCCountry option:selected').attr('phonecode'));
		if(countryname=="United States")
		{
			$(".province").css("display","none");
			$(".state").css("display","block");
		}
		else
		{
			$(".province").css("display","block");
			$(".state").css("display","none");
		}
	});
	$('select[name=\'CCCountry\']').trigger('change');
	
});
function submitform(e)
{
	var htmlresult="";
	<?php
	$i=0;
	foreach($cart as $item)
	{
	
	?>
		var extraparam=<?php echo json_encode($item['extraparam']); ?>;
		
		$.ajax({
			type: "POST",
			url: "<?=base_url('enom/purchase').'/'.$item['ptype']?>",
			dataType:'json',
			data: $("#purchaseform").serialize() +"&sld=<?=$item['sld']?>&tld=<?=$item['tld']?>&domainid=<?=$item['itemid']?>&productid=<?=$item['productid']?>&qty=<?=$item['qty']?>&price=<?=$item['price']?>&extraparam="+JSON.stringify(extraparam),
			async:false,
			beforeSend: function() {
				$(e).attr('disabled','disabled');
				$(e).before('<span class="wait">&nbsp;<img src="<?php echo base_url()?>assets/front/img/ajax-loader.gif" alt="" /></span>');
			},
			success: function(json){
				if(json['message'])
				{
					if(json['message']['success'])
					{
						$('#ajax_msg').html('<div class="alert alert-success alert-dismissable flashmsg"><button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>'+ json['message']['success'] + '</div>');
					}
					else{
						$('#ajax_msg').html('<div class="alert alert-success alert-dismissable flashmsg"><button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>'+ json['message']['error'] + '</div>');
					}
					$('#ajax_msg .flashmsg').delay(5000).fadeOut('slow');
					$('html, body').animate({ scrollTop: 0 }, 'slow');
					$(e).removeAttr('disabled');
					$(".wait").remove();
					if(json['message']['success'])
					{
						$.post('<?php echo base_url('enom/removecart');?>',{ rowid: "<?=$item['rowid']?>", itemid: "<?=$item['itemid']?>",qty: 0 }, function(cart){
							$(".cart_content").html(cart['carthtml']);
						},'json');
					}
				}
				if(json['htmlresult']!="")
				{
					htmlresult=json['htmlresult'];
				}
				
			}
		});
	<?}
	?>
	if(htmlresult!="")
	{
	$('#contentwrapperinner').html(htmlresult);
	}
	return false;
}
</script>